package cn.gjh.bookmanager.controller;

import cn.gjh.bookmanager.entity.Ebookentry;
import cn.gjh.bookmanager.service.EbookentryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TestController {
    @Resource
    private EbookentryService ebookentryService;

    @RequestMapping("/testM")
    @ResponseBody
    public String testProject(){
        return "测试";
    }

    @RequestMapping("/login")
    public String login(){
        return "login";
    }




    @RequestMapping("/ZengJia")
    public String inset(){
        return "insert";
    }



    @RequestMapping("/getZhuYe")
    @ResponseBody
    public Object getZhuye(Integer categroyid,Integer page,Integer limit){
        Integer startNum = (page -1)*limit;
        //获取每一页的条数
        List<Ebookentry> ebookentriesList =
                ebookentryService.queryEbookEntryList(categroyid,startNum,limit);
        Map<String,Object> result = new HashMap<>();
        result.put("data",ebookentriesList);
        result.put("code",0);
        result.put("count",10);

        return result;
    }


    @RequestMapping("/delete/{id}")
    @ResponseBody
    public  Object delete(@PathVariable Integer id){
        Map<String,Object> result = new HashMap();
        int shanchu = ebookentryService.delete(id);
        result.put("code",0);
        result.put("mark",shanchu);
        return result;
    }

    @RequestMapping("/xiugaibook")
    @ResponseBody
    public Object getUpdate(Ebookentry ebookentry){
        //获取每一页的条数

            int ebookupda = ebookentryService.updateEbookentry(ebookentry);
            Map<String,Object> result = new HashMap<>();

            result.put("code",0);
            result.put("mark",ebookupda);

            return  result;

    }

    @RequestMapping("/InsertEbook")
    @ResponseBody
    public Object getInsert(Ebookentry ebookentry){
        //获取每一页的条数

        int ebookupda = ebookentryService.insertEbookentry(ebookentry);
        Map<String,Object> result = new HashMap<>();

        result.put("code",0);
        result.put("mark",ebookupda);

        return  result;

    }
}
